package com.xl.service.impl;

import com.xl.dao.UserDao;
import com.xl.mapper.SysConfigMapper;
import com.xl.pojo.SysConfig;
import com.xl.service.UserService;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.web.context.ServletContextAware;

import javax.servlet.ServletContext;
import java.util.List;

public class UserServiceImpl implements UserService, InitializingBean, ServletContextAware,
        ApplicationContextAware, BeanFactoryAware, BeanNameAware {

    //需要SysConfigMapper
    private SysConfigMapper sysConfigMapper;

    public void setSysConfigMapper(SysConfigMapper sysConfigMapper) {
        this.sysConfigMapper = sysConfigMapper;
    }

    public void show() {
        List<SysConfig> list = sysConfigMapper.findAll();
        for (SysConfig s : list) {
            System.out.println(s);
        }
    }

    //注入list
    private List<String> stringList;
    public void setStringList(List<String> stringList) {
        this.stringList = stringList;
    }
    //注入UserDao类型的list
    private List<UserDao> userDaoList;
    public void setUserDaoList(List<UserDao> userDaoList) {
        this.userDaoList = userDaoList;
    }

    /*public void show () {
        //System.out.println("stringList:"+stringList);
        //System.out.println("userDaoList:"+userDaoList);
        System.out.println(userDao);
    }*/
    public void init() {
        System.out.println("初始化方法...");
    }

    public void destroy() {
        System.out.println("销毁方法...");
    }

    public UserServiceImpl() {
        //System.out.println("UserServiceImpl实例化");
        System.out.println("UserServiceImpl无参构造方法");
    }

    public UserServiceImpl(String name) {
        //System.out.println("UserServiceImpl实例化");
        System.out.println("UserServiceImpl有参构造方法");
    }

    private UserDao userDao;
    /**
     * BeanFactory去调用该方法，从容器中获得userDao设置到此处
     * @param userDao
     */
    public void setUserDao(UserDao userDao) {
        System.out.println("BeanFactory去调用该方法获得userDao设置到此处："+userDao);
        this.userDao = userDao;
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("afterPropertiesSet方法执行...");
    }

    @Override
    public void setServletContext(ServletContext servletContext) {
        System.out.println("servletContext:"+servletContext);
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println("applicationContext:"+applicationContext);
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        System.out.println("beanFactory:"+beanFactory);
    }

    @Override
    public void setBeanName(String s) {
        System.out.println("beanName:"+s);
    }
}
